package com.neu.controller;


import com.github.pagehelper.PageInfo;
import com.neu.common.Result;
import com.neu.entity.Hotel;
import com.neu.entity.Params;
import com.neu.service.BookService;
import com.neu.service.HotelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/hotel")
public class HotelController {
    @Autowired
    private HotelService hotelService;

    @GetMapping("/search")
    public Result findBySearch(Params params){
        PageInfo<Hotel> info = hotelService.findBySearch(params);
        return Result.success(info);
    }

    @PostMapping
    public Result add(@RequestBody Hotel hotel){
        if(hotel.getId() == null){
            hotelService.add(hotel);
        }else{
            hotelService.update(hotel);
        }

        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        hotelService.delete(id);
        return Result.success();
    }
}
